package mvstore;

import cn.secsmart.commons.proxy.ProxyType;
import com.alibaba.fastjson.JSON;
import java.util.Date;
import net.secsmart.dm.service.impl.ProxyProcessInfo;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;

public class MVStore2 {

    public static void main(String[] args) {
        System.out.println(new Date(1568682313896L));

        testLocalWrite();
        testLocalRead();

        testRemote();
    }

    private static void testRemote() {
        // open the store (in-memory if fileName is null)
        MVStore s = MVStore.open("/Users/dingjianfeng/IdeaProjects/GitTest/src/main/java/mvstore/data");

// create/get the map named "data"
        MVMap<String, Object> map = s.openMap("proxyProcessInfo");

        /***
         * latestAlgJarPathKey -> /opt/ddm-proxy/lib_alg/
         * latestDisJarPathKey -> /opt/ddm-proxy/lib_dis/
         */
        MVMap<String, String> map2 = s.openMap("extraJarPath");
        map2.keySet().stream().forEach(e -> System.out.println(e + "--->" + map2.get(e)));
        map.keySet().stream().forEach(e -> System.out.println(e));
        //map.keySet().stream().forEach(e-> System.out.println(e+"--->"+JSON.toJSONString(map.get(e))));
        //map.keySet().stream().forEach(e-> System.out.println(JSON.toJSONString(map.get(e))));
    }

    private static void testLocalWrite() {
        MVStore s2 = MVStore.open("/Users/dingjianfeng/IdeaProjects/GitTest/src/main/java/mvstore/data2");
        MVMap<String, ProxyProcessInfo> mapp = s2.openMap("proxyProcessInfo");
        ProxyProcessInfo proxyProcessInfo = new ProxyProcessInfo();
        proxyProcessInfo.setPort(9999);
        proxyProcessInfo.setProxyId("222");
        proxyProcessInfo.setProxyType(ProxyType.HBase_2_0_5);
        proxyProcessInfo.setTimestamp(System.currentTimeMillis());
        mapp.put("djf", proxyProcessInfo);
        s2.close();

    }

    private static void testLocalRead() {
        MVStore s2 = MVStore.open("/Users/dingjianfeng/IdeaProjects/GitTest/src/main/java/mvstore/data2");
        MVMap<String, ProxyProcessInfo> mapp = s2.openMap("proxyProcessInfo");
        mapp.keySet().stream().forEach(e -> System.out.println(JSON.toJSONString(mapp.get(e))));

    }
}
